package QuizUI;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import QuizPackage.*;

/**
 * Servlet implementation class StoreQuestion
 */
@WebServlet("/StoreQuestion")
public class StoreQuestion extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public StoreQuestion() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		int quizid = Integer.parseInt(request.getParameter("quizid"));
		String qtype = request.getParameter("qtype");
		if(qtype.equals("questionresponse"))
		{
			QuestionResponse.submitQuestion(quizid,request);
		}
		else if(qtype.equals("fillinblank"))
		{
			FillInBlank.submitQuestion(quizid,request);
		}
		else if(qtype.equals("pictureresponse"))
		{
			PictureResponse.submitQuestion(quizid,request);
		}
		else if(qtype.equals("multipleresponse"))
		{
			MultiAnswer.submitQuestion(quizid,request);
		}
		else if(qtype.equals("multiplechoice"))
		{
			MultipleChoice.submitQuestion(quizid,request);
		}
		request.setAttribute("quizid",quizid);
		
		RequestDispatcher dispatch = request.getRequestDispatcher("AddQuestion.jsp");
		dispatch.forward(request,response);
	}

}
